home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Main.bin / VPOJAVA.DLL / SOURCE / QUITDIALOG < prev    next >
Text File  |  1998-12-10  |  5KB  |  184 lines

  1. /*
  2.     A basic extension of the java.awt.Dialog class
  3.  */
  4.  
  5. import java.awt.*;
  6. import java.awt.event.*;
  7.  
  8. public class QuitDialog extends Dialog
  9. {
  10.     public QuitDialog(Frame parent, boolean modal)
  11.     {
  12.         super(parent, modal);
  13.  
  14.         //Keep a local reference to the invoking frame
  15.         frame = parent;
  16.         
  17.         // This code is automatically generated by Visual Cafe when you add
  18.         // components to the visual environment. It instantiates and initializes
  19.         // the components. To modify the code, only use code syntax that matches
  20.         // what Visual Cafe can generate, or Visual Cafe may be unable to back
  21.         // parse your Java file into its visual environment.
  22.         //{{INIT_CONTROLS
  23.         setLayout(null);
  24.         setSize(337,135);
  25.         setVisible(false);
  26.         yesButton.setLabel(" Yes ");
  27.         add(yesButton);
  28.         yesButton.setFont(new Font("Dialog", Font.BOLD, 12));
  29.         yesButton.setBounds(72,80,79,22);
  30.         noButton.setLabel("  No  ");
  31.         add(noButton);
  32.         noButton.setFont(new Font("Dialog", Font.BOLD, 12));
  33.         noButton.setBounds(185,80,79,22);
  34.         label1.setText("Do you really want to exit?");
  35.         label1.setAlignment(java.awt.Label.CENTER);
  36.         add(label1);
  37.         label1.setBounds(78,33,180,23);
  38.         setTitle("AWT Application - Exit");
  39.         //}}
  40.  
  41.         //{{REGISTER_LISTENERS
  42.         SymWindow aSymWindow = new SymWindow();
  43.         this.addWindowListener(aSymWindow);
  44.         SymAction lSymAction = new SymAction();
  45.         noButton.addActionListener(lSymAction);
  46.         yesButton.addActionListener(lSymAction);
  47.         //}}
  48.     }
  49.  
  50.     public void addNotify()
  51.     {
  52.         // Record the size of the window prior to calling parents addNotify.
  53.         Dimension d = getSize();
  54.         
  55.         super.addNotify();
  56.  
  57.         if (fComponentsAdjusted)
  58.             return;
  59.  
  60.         // Adjust components according to the insets
  61.         setSize(getInsets().left + getInsets().right + d.width, getInsets().top + getInsets().bottom + d.height);
  62.         Component components[] = getComponents();
  63.         for (int i = 0; i < components.length; i++)
  64.         {
  65.             Point p = components[i].getLocation();
  66.             p.translate(getInsets().left, getInsets().top);
  67.             components[i].setLocation(p);
  68.         }
  69.         fComponentsAdjusted = true;
  70.     }
  71.  
  72.     public QuitDialog(Frame parent, String title, boolean modal)
  73.     {
  74.         this(parent, modal);
  75.         setTitle(title);
  76.     }
  77.  
  78.     /**
  79.      * Shows or hides the component depending on the boolean flag b.
  80.      * @param b  if true, show the component; otherwise, hide the component.
  81.      * @see java.awt.Component#isVisible
  82.      */
  83.     public void setVisible(boolean b)
  84.     {
  85.         if(b)
  86.         {
  87.             Rectangle bounds = getParent().getBounds();
  88.             Rectangle abounds = getBounds();
  89.     
  90.             setLocation(bounds.x + (bounds.width - abounds.width)/ 2,
  91.                  bounds.y + (bounds.height - abounds.height)/2);
  92.             Toolkit.getDefaultToolkit().beep();
  93.         }
  94.         super.setVisible(b);
  95.     }
  96.  
  97.     // Used for addNotify check.
  98.     boolean fComponentsAdjusted = false;
  99.     // Invoking frame
  100.     Frame frame = null;
  101.  
  102.     //{{DECLARE_CONTROLS
  103.     java.awt.Button yesButton = new java.awt.Button();
  104.     java.awt.Button noButton = new java.awt.Button();
  105.     java.awt.Label label1 = new java.awt.Label();
  106.     //}}
  107.  
  108.     class SymAction implements java.awt.event.ActionListener
  109.     {
  110.         public void actionPerformed(java.awt.event.ActionEvent event)
  111.         {
  112.             Object object = event.getSource();
  113.             if (object == yesButton)
  114.                 yesButton_ActionPerformed(event);
  115.             else if (object == noButton)
  116.                 noButton_ActionPerformed(event);
  117.         }
  118.     }
  119.  
  120.     void yesButton_ActionPerformed(java.awt.event.ActionEvent event)
  121.     {
  122.         // to do: code goes here.
  123.              
  124.         yesButton_ActionPerformed_Interaction1(event);
  125.     }
  126.  
  127.  
  128.     void yesButton_ActionPerformed_Interaction1(java.awt.event.ActionEvent event)
  129.     {
  130.         try {
  131.             frame.setVisible(false);    // Hide the invoking frame
  132.             frame.dispose();            // Free system resources
  133.             this.dispose();                  // Free system resources
  134.             System.exit(0);             // close the application
  135.         } catch (Exception e) {
  136.         }
  137.     }
  138.  
  139.  
  140.     void noButton_ActionPerformed(java.awt.event.ActionEvent event)
  141.     {
  142.         // to do: code goes here.
  143.              
  144.         noButton_ActionPerformed_Interaction1(event);
  145.     }
  146.  
  147.  
  148.     void noButton_ActionPerformed_Interaction1(java.awt.event.ActionEvent event)
  149.     {
  150.         try {
  151.             this.dispose();
  152.         } catch (Exception e) {
  153.         }
  154.     }
  155.  
  156.  
  157.     class SymWindow extends java.awt.event.WindowAdapter
  158.     {
  159.         public void windowClosing(java.awt.event.WindowEvent event)
  160.         {
  161.             Object object = event.getSource();
  162.             if (object == QuitDialog.this)
  163.                 QuitDialog_WindowClosing(event);
  164.         }
  165.     }
  166.  
  167.     void QuitDialog_WindowClosing(java.awt.event.WindowEvent event)
  168.     {
  169.         // to do: code goes here.
  170.              
  171.         QuitDialog_WindowClosing_Interaction1(event);
  172.     }
  173.  
  174.  
  175.     void QuitDialog_WindowClosing_Interaction1(java.awt.event.WindowEvent event)
  176.     {
  177.         try {
  178.             this.dispose();
  179.         } catch (Exception e) {
  180.         }
  181.     }
  182.  
  183. }
  184.